﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    


<head>
	<script type="text/javascript">
		$(function(){
				init();
		});
		
			function init(){
				$('#t-dg').datagrid({
				loadMsg:''
				
			});
				
			}

		

		

		var actionUrl;
		function newItem(){
			$('#dlg').dialog('setTitle', '新增链接').dialog('open');
			$('#myform').form('clear');
			actionUrl = '<c:url value="/portal/Link/saveLink"/>';
		}
		function editItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				$('#myform').form('load', row);
				$('#dlg').dialog('setTitle', '修改链接').dialog('open');
				actionUrl = '<c:url value="/portal/Link/updateLink"/>?id=' + row.id;
			}
		}
		
		function deleteItem(){
			var t = $('#t-dg');
			var row = t.datagrid('getSelected');
			if (row){
				
				$.messager.confirm('删除确认', '是否确定要删除选择链接?', function(r){
						if (r){
				$.ajax({
					url:'<c:url value="/portal/Link/destroyLink"/>?id=' + row.id,
					type:'post',
					success:function(){
						$('#t-dg').datagrid('reload');
					}
				});
			}});
				
			}
		}
		
		function saveItem(){
			$('#myform').form('submit', {
				url:actionUrl,
				onSubmit:function(){
					return $('#myform').form('validate');
				},
				success:function(data){
					var data = eval('('+data+')');
					if (data.success){
						$('#dlg').dialog('close');
						$('#t-dg').datagrid('reload');
					} else {
						$.messager.show({
							title:'保存失败',
							msg:'<pre>'+data.msg+'</pre>'
						});
					}
				}
			});
		}
		function doQuery(value){
			$('#t-dg').datagrid('load', {
				q: value
			});
		}
		
		function formattotop(value){
			if (value == "1") 
				return "<font color=red>置顶</font>";
			if (value == "0") 
				return "<font color=blue>不置顶</font>";

			}
	</script>
</head>
<body>
	<div class="easyui-layout" fit="true">
		<div region="north" border="false" style="height:40px;padding:5px;overflow:hidden;">
			<div style="padding-top:3px;float:left">
			<input class="easyui-searchbox" prompt="按网站名称|简称|链接进行查询" searcher="doQuery" style="width:300px"></input>
		</div>
		<div style="float:left">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newItem()">新增链接</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editItem()">修改链接</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteItem()">删除链接</a>			
		</div>
	</div>
		
		
		<div region="center" border="false">
			<table id="t-dg" style="display:none;"
					url="<c:url value='/portal/Link/getLinkItems'/>"
					singleSelect="true" rownumbers="true" pagination="true"
					border="false" fit="true" fitColumns="true">
				<thead>
					<tr>
						<th field="name" width="100" sortable="true">网站名称</th>
<th field="sxname" width="100" sortable="true">简称</th>
<th field="url" width="100" sortable="false">链接</th>
<th field="logourl" width="100" sortable="false">图标链接</th>
<th field="totop" width="100" sortable="true" formatter="formattotop">置顶</th>
<th field="sort" width="100" sortable="true">排序</th>

					</tr>
				</thead>
			</table>
		</div>
	</div>
	
<div id="dlg" style="width:400px;height:250px;"
			class="easyui-dialog" closed="true" modal="true" buttons="#dlg-buttons">
		<div style="padding:10px">
			<div style="float:left">
				<form id="myform" method="post" style="margin:0;padding:0">
					<table>
						<tr>
<td style="width:80px">网站名称</td>
<td><input type="text" class="easyui-validatebox e-input" id="name" name="name" style="width:250px;" data-options="required:true,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">简称</td>
<td><input type="text" class="easyui-validatebox e-input" id="sxname" name="sxname" style="width:250px;" data-options="required:true,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">链接</td>
<td><input type="text" class="easyui-validatebox e-input" id="url" name="url" style="width:250px;" data-options="required:true,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">图标链接</td>
<td><input type="text" class="easyui-validatebox e-input" id="logourl" name="logourl" style="width:250px;" data-options="required:false,editable:true" ></input></td>
</tr>	
<tr>
<td style="width:80px">置顶</td>
<td>
<select id="totop" name="totop" 
	data-options="required:true,editable:false" panelHeight="auto" class="easyui-combobox" style="width:255px;">
		<option value="1">首页</option>
		<option value="0">内页</option>		
</select></td>
</tr>	


<tr>
<td style="width:80px">排序</td>
<td><input type="text" class="easyui-numberbox" precision="0" id="sort" name="sort" style="width:250px;" data-options="required:true,editable:true" ></input></td>
</tr>	
								
					</table>
				</form>
			</div>			
			<div style="clear:both"></div>
		</div>
		<div id="dlg-buttons" style="text-align:center;">
			<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="saveItem()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
		</div>
</div>

	

</body>
